package org.javaboy.vhr.mapper;

import org.apache.ibatis.annotations.*;
import org.javaboy.vhr.model.CarManager;
import org.javaboy.vhr.model.Manager;
import org.javaboy.vhr.model.RespPageBean;

import java.util.Date;
import java.util.List;

/**
 * ClassName: CarManagerMapper <br/>
 * Description: <br/>
 * date: 2020/3/21 21:01<br/>
 *
 * @author Hesion<br />
 * @since JDK 1.8
 */
@Mapper
public interface CarManagerMapper {
    @Select({"<script> " +
            "SELECT * FROM manager  WHERE del_flag = '0'" +
            "<if test=\"manager.mname != null and manager.mname != ''\">" +
            "AND mname like concat('%',#{manager.mname},'%')</if>" +
            "<if test=\"page != null and size != null\">" +
            "limit #{page},#{size}</if>" +
            "</script>"})
    @Results(id = "ManagerinfoResult",
            value = {
                    @Result(property = "createTime", column = "create_time"),
                    @Result(property = "updateTime", column = "update_time"),
                    @Result(property = "createBy", column = "create_by"),
                    @Result(property = "updateBy", column = "update_by"),
            })
    List<Manager> getManagerByPage(Integer page, Integer size, Manager manager, Date[] beginDateScope);

    @Select({"<script> " +
            "SELECT count(*) FROM manager  where del_flag = '0'" +
            "<if test=\"manager.mname != null\">" +
            "and mname=#{manager.mname}</if>" +
            "</script>"})
    Long getTotal(Manager manager, Date[] beginDateScope);

    @Select("SELECT * FROM v_carManager WHERE cId=#{cId}")
    @Results(id = "showCarManagerResult",
            value = {
                    @Result(property = "createTime", column = "create_time"),
                    @Result(property = "updateTime", column = "update_time"),
                    @Result(property = "createBy", column = "create_by"),
                    @Result(property = "updateBy", column = "update_by"),
            })
    List<Manager> showCarManager(String cId);

    @Update("UPDATE manager SET update_by=#{createBy},update_time=#{createTime} WHERE id=#{mId}")
    int updateManager(CarManager carManager);
}
